const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

const {Login} = require('../../api/index')
Page({
  data: {
    userInfo: {},
    avatarUrl: defaultAvatarUrl,
    nickname: '',
    list:[
        {
            text:'前端',
            icon:'like',
            color:"green"
        },
        {
            text:'python',
            icon:'star',
            color:"red"
        },
        {
            text:'后端',
            icon:'fire',
            color:"black"
        },
        {
            text:'大数据',
            icon:'service',
            color:"pink"
        },
        {
            text:'考研',
            icon:'cluster',
            color:"orange"
        },
        {
            text:'四六级',
            icon:'manager',
            color:"blue"
        },
    ]
  },
  onLoad(options) {
    if(wx.getStorageSync('avatarUrl')) {
        this.setData({
            avatarUrl:wx.getStorageSync('avatarUrl')
        })
    }

    if(wx.getStorageSync('nickname')) {
        this.setData({
            nickname:wx.getStorageSync('nickname')
        })
    }
  },
  onChooseAvatar(e) {
      console.log(e);
    const { avatarUrl } = e.detail
    this.setData({
      avatarUrl,
    })
    this.loginHandle()
      wx.getStorageSync('avatarUrl',this.data.avatarUrl)
  },
  onInputNickname(e) {
    this.setData({
      nickname: e.detail.value
    })
    console.log(this.data.nickname);
      wx.getStorageSync('nickname',this.data.nickname)

  },
  loginHandle(){
      wx.login({
        success: (res) => {
          // code
          console.log(res.code);
          Login({code:res.code}).then(res => {
              console.log(res.data);
    
              wx.getStorageSync('loginID',res.data.data)

          })
        },
        fail:(res) =>{
            wx.showToast({
              title: '登录失败',
            })
        }
      })
  }
})